package com.icinfo.cloud.provider.punish.simple.transfer.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.icinfo.cloud.provider.common.enums.CertTypeEnum;
import com.icinfo.cloud.provider.common.enums.YesOrNoEnum;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.vo.MemberDeptVo;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.vo.MemberOrgVo;
import com.icinfo.cloud.provider.punish.simple.transfer.model.CaseSimpleTransferRecord;
import lombok.Data;

import javax.persistence.Column;
import java.util.Date;
import java.util.Map;
import java.util.Objects;

/**
 * 简单案件移交信息分页列表返回参数
 * @author HKxxx
 * @date 2024/2/1 15:33
 */
@Data
public class CaseSimpleTransferRecordPageVo {

    private String id;

    /**
     * 当事人
     */
    private String partyName;

    /**
     * 事项名称
     */
    private String itemName;


    /**
     * 委托单位
     */
    private String entrustOrgName;

    /**
     * 事项代码
     */
    private String itemCode;

    /**
     * 统一社会信用代码
     */
    private String uniscid;

    /**
     * 个人/法人证件类型
     */
    private String certType;

    /**
     * 个人/法人证件号码
     */
    private String certCode;

    /**
     * 是否无牌  （1-是 0-否）
     */
    private String hasLicensePlate;

    /**
     * 是否无证 （1-是 0-否）
     */
    private String hasDrivingLicence;

    /**
     * 办案单位
     */
    private String handleOrgName;

    /**
     * 办案部门
     */
    private String handleDeptName;

    /**
     * 主办人
     */
    private String mainHandlePerson;

    /**
     * 协办人
     */
    private String assistHandlePerson;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date createTime;

    public static CaseSimpleTransferRecordPageVo convertPageVo(CaseSimpleTransferRecord record,
                                                               Map<String, MemberOrgVo> orgVos,
                                                               Map<String, MemberDeptVo> deptVos){
        CaseSimpleTransferRecordPageVo vo = new CaseSimpleTransferRecordPageVo();
        vo.setId(record.getId());
        vo.setPartyName(record.getPartyName());
        vo.setItemName(record.getItemName());
        // 委托部门
        MemberDeptVo entrustDept = deptVos.get(record.getEntrustDeptCode());
        vo.setEntrustOrgName(Objects.nonNull(entrustDept) ? entrustDept.getDeptShortName() : "");
        vo.setItemCode(record.getItemCode());
        vo.setUniscid(record.getUniscid());
        vo.setCertType(CertTypeEnum.getValueByCode(record.getCertType()));
        vo.setCertCode(record.getCertCode());
        vo.setHasLicensePlate(YesOrNoEnum.getValueByCode(record.getHasLicensePlate()));
        vo.setHasDrivingLicence(YesOrNoEnum.getValueByCode(record.getHasDrivingLicence()));
        // 办案单位
        MemberOrgVo handleOrg = orgVos.get(record.getHandleOrgCode());
        vo.setHandleOrgName(Objects.nonNull(handleOrg) ? handleOrg.getOrgShortName() : "");
        // 办案单位
        MemberDeptVo handleDept = deptVos.get(record.getHandleDeptCode());
        vo.setHandleDeptName(Objects.nonNull(handleDept) ? handleDept.getDeptShortName() : "");
        vo.setMainHandlePerson(record.getMainHandlePerson());
        vo.setAssistHandlePerson(record.getAssistHandlePerson());
        vo.setCreateTime(record.getCreateTime());
        return vo;
    }

}
